package cn.lu.utils;


/**
 * 通用返回的类
 * @author Administrator
 */

public class Result {
    /**
     * 0    -   成功
     * 1    -   失败
     * 500  -   服务器内部错误
     */
    private int code;
    //提示信息
    private String Msg;
    //用户要返回给浏览器的数据
    private Object data = new Object();

    public Result() {

    }

    public Result(int code, String msg, Object data) {
        this.code = code;
        Msg = msg;
        this.data = data;
    }

    public static Result success(Object data) {
        Result result = new Result();
        result.setMsg("成功");
        result.setCode(0);
        result.setData(data);
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setMsg("成功");
        result.setCode(0);
        result.setData("success");
        return result;
    }

    public static Result fail(Object data) {
        Result result = new Result();
        result.setCode(1);
        result.setMsg("失敗");
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setCode(1);
        result.setMsg("失敗");
        result.setData("error");
        return result;
    }

    public static Result errorServer(Object data) {
        Result result = new Result();
        result.setCode(500);
        result.setMsg("服务器内部错误");
        result.setData(data);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return Msg;
    }

    public void setMsg(String Msg) {
        this.Msg = Msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
